package com.servlet;

import com.dao.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/check")
public class CheckServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            check(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            check(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    //查
    public static void check(HttpServletRequest req, HttpServletResponse resp) throws SQLException, ServletException, IOException {
        Student student = new Student();
        List list = null;
        try {
            list = student.check();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        System.out.println(list);
        req.setAttribute("users", list);
        req.getRequestDispatcher("list.jsp").forward(req, resp);
    }
}
